package com.printeverywhere.util;

import java.rmi.RemoteException;

import javax.xml.rpc.ServiceException;

import org.apache.axis.AxisFault;

import NET.webserviceX.www.Currency;
import NET.webserviceX.www.CurrencyConvertorLocator;
import NET.webserviceX.www.CurrencyConvertorSoap;

public class CurrencyConverter {

	/**
	 * @param args
	 */
	public static double conversionRate(Currency currencyFrom, Currency currencyTo) {
		double conversionRate = 1.0;

		try {
			if(!currencyFrom.equals(currencyTo)) {
				CurrencyConvertorLocator currencyConvertorLocator = new CurrencyConvertorLocator();
				CurrencyConvertorSoap currencyConvertorSoap = currencyConvertorLocator.getCurrencyConvertorSoap();
				conversionRate = currencyConvertorSoap.conversionRate(currencyFrom, currencyTo);
			}
		} catch (AxisFault e) {
			e.printStackTrace();
		} catch (RemoteException e) {
			e.printStackTrace();
		} catch (ServiceException e) {
			e.printStackTrace();
		}

		return conversionRate;
	}
}
